import {PostsState} from '.';
import {
  RestStateAction,
  SetIdAction,
  SetThumbUrlAction,
  SetContentAction,
  SetTypeAction,
  SetCreateTimeAction,
  SetUpdateTimeAction,
  SetTitleAction,
  PostsActionType
} from './interface';

export const restState = (): RestStateAction => ({
  type: PostsActionType.RESET_STATE
});

export const setId = (payload: Pick<PostsState, 'id'>): SetIdAction => ({
  type: PostsActionType.SET_ID,
  payload
});

export const setType = (payload: Pick<PostsState, 'type'>): SetTypeAction => ({
  type: PostsActionType.SET_TYPE,
  payload
});

export const setThumbUrl = (
  payload: Pick<PostsState, 'thumb_url'>
): SetThumbUrlAction => ({
  type: PostsActionType.SET_THUMB_URL,
  payload
});

export const setContent = (
  payload: Pick<PostsState, 'content'>
): SetContentAction => ({
  type: PostsActionType.SET_CONTENT,
  payload
});

export const setCreateTime = (
  payload: Pick<PostsState, 'create_time'>
): SetCreateTimeAction => ({
  type: PostsActionType.SET_CREATE_TIME,
  payload
});

export const setUpdateTime = (
  payload: Pick<PostsState, 'update_time'>
): SetUpdateTimeAction => ({
  type: PostsActionType.SET_UPDATE_TIMR,
  payload
});

export const setTitle = (
  payload: Pick<PostsState, 'title'>
): SetTitleAction => ({
  type: PostsActionType.SET_TITLE,
  payload
});
